import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class ProjectManageService {

  serviceUrls = {
    uploadPackageUrl: '/projectVersion/uploadPackage', // 上传项目包

    queryProjectListUrl: '/project/find', // 查询项目列表
    saveProjectUrl: '/project/save', // 新增项目
    updateProjectUrl: '/project/update', // 编辑项目
    deleteProjectUrl: '/project/delete', // 删除项目

    projectEditionListUrl: '/projectVersion/find', // 查询项目版本List
    saveProEditionUrl: '/projectVersion/save', // 新增项目版本
    updateProEditionUrl: '/projectVersion/update', // 编辑项目版本
    deleteProEditionUrl: '/projectVersion/delete', // 删除项目版本
  };

  constructor(public httpClient: HttpClient) { }

  /**
   * 上传项目包
   * @param packageFile 
   * @param platform 平台 1为ios 2为安卓 3为Windows
   * @returns 
   */
  uploadPackageData(packageFile: File, platform: string) {
    const formData: FormData = new FormData();
    formData.append('packageFile', packageFile);
    formData.append('platform', platform);
    return this.httpClient.post(this.serviceUrls.uploadPackageUrl, formData).toPromise();
  }

  // 查询项目列表
  queryProjectListData(params: any): Promise<any> {
    return this.httpClient.post(this.serviceUrls.queryProjectListUrl, params).toPromise();
  }

  // 新增项目
  saveProjectItem(params: any) {
    return this.httpClient.post(this.serviceUrls.saveProjectUrl, params).toPromise();
  }

  // 编辑项目
  updateProjectItem(params: any) {
    return this.httpClient.post(this.serviceUrls.updateProjectUrl, params).toPromise();
  }

  // 删除项目
  deleteProjectItem(params: any) {
    return this.httpClient.post(this.serviceUrls.deleteProjectUrl, params).toPromise();
  }

  // 查询项目版本List
  queryProjectEditionList(params: any) {
    return this.httpClient.post(this.serviceUrls.projectEditionListUrl, params).toPromise();
  }

  // 新增项目版本
  saveProEditionItem(params: any) {
    return this.httpClient.post(this.serviceUrls.saveProEditionUrl, params).toPromise();
  }

  // 编辑项目版本
  updateProEditionItem(params: any) {
    return this.httpClient.post(this.serviceUrls.updateProEditionUrl, params).toPromise();
  }

  // 删除项目版本
  deleteProEditionItem(params: any) {
    return this.httpClient.post(this.serviceUrls.deleteProEditionUrl, params).toPromise();
  }
}

